<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工作台账数据格式化</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <style>
        table {
            word-break:break-all; 
            word-wrap:break-word;
            table-layout:auto;
        }
        td {
            width: 10rem;
        }
    </style>
    <script src="./../js/index.js"></script>
</head>

<body>
    <div class="container">
        <nav class="navbar bg-body-tertiary">
            <form class="container-fluid justify-content-start">
              <button class="btn btn-outline-success me-2 active" type="button" >台账</button>
              <button class="btn btn-outline-success me-2" type="button" onclick="to_demo1()" >掉线</button>
              <button class="btn btn-outline-success me-2" type="button" onclick="to_index()" >测试</button>
            </form>
          </nav>
        </div>
     
    <div class="container-sm">
        <table class="table table-striped">
            <thead>
                
            </thead>
            <tbody>
                <tr>
                    
                    <td id="t1d1" class="col-sm-1"></td>
                    <td id="t1d2" class="col-sm-1"></td>
                    <td id="t1d3" class="col-sm-1"></td>
                    <td id="t1d4" class="col-sm-8"></td>
                </tr>
                <tr>
                    
                    <td id="t2d1"></td>
                    <td id="t2d2"></td>
                    <td id="t2d3"></td>
                    <td id="t2d4"></td>
                </tr>
                <tr>
                    
                    <td id="t3d1"></td>
                    <td id="t3d2"></td>
                    <td id="t3d3"></td>
                    <td id="t3d4"></td>
                </tr>
                <tr>
                    
                    <td id="t4d1"></td>
                    <td id="t4d2"></td>
                    <td id="t4d3"></td>
                    <td id="t4d4"></td>
                </tr>
                <tr>
                    
                    <td id="t5d1"></td>
                    <td id="t5d2"></td>
                    <td id="t5d3"></td>
                    <td id="t5d4"></td>
                </tr>
                <tr>
                    
                    <td id="t6d1"></td>
                    <td id="t6d2"></td>
                    <td id="t6d3"></td>
                    <td id="t6d4"></td>
                </tr>
                <tr>
                    
                    <td id="t7d1"></td>
                    <td id="t7d2"></td>
                    <td id="t7d3"></td>
                    <td id="t7d4"></td>
                </tr>
                <tr>
                    
                    <td id="t8d1"></td>
                    <td id="t8d2"></td>
                    <td id="t8d3"></td>
                    <td id="t8d4"></td>
                </tr>

            </tbody>
        </table>
    </div>
    <br>
    <div class="container-sm">
        
            
        </div>
	
        <div class="form-group">
            <textarea class="form-control" rows="3" id="inputinfo" placeholder="粘贴示例 ：粤XXXX
            驾驶员: -
            定位时间: XXXX
            定位经度: XXX
            定位纬度: XXX
            行驶速度: XXkm/h
            轨迹里程: XXkm
            行驶方向: XX
            定位位置: XXX"></textarea>
        </div>
<div class="form-group">
            <textarea class="form-control" rows="6"  placeholder="粘贴车牌"></textarea>
        </div>

    </div>


    <script>



        document.onkeydown = function(e){
            var ev = document.all ? window.event : e;
            if(ev.keyCode==13) {
                add()
            }
        }


        function add() {
            //var lineNum = blankLine() 
            setValue()
            document.getElementById("inputinfo").value=null
            //var inputinfo = document.getElementById("inputinfo").value

            //document.getElementById("show").value = inputinfo
            //document.getElementById("t1d1").innerHTML = inputinfo
        }

        // 判断空行
        function blankLine() {

            if (document.getElementById("t1d1").innerHTML == '' && document.getElementById("t1d2").innerHTML == '' && document.getElementById("t1d3").innerHTML == '') {

                return 1
            }

            if (document.getElementById("t2d1").innerHTML == '' && document.getElementById("t2d2").innerHTML == '' && document.getElementById("t2d3").innerHTML == '') {

                return 2
            }
  
            if (document.getElementById("t3d1").innerHTML == '' && document.getElementById("t3d2").innerHTML == '' && document.getElementById("t3d3").innerHTML == '') {

                return 3
            }
            if (document.getElementById("t4d1").innerHTML == '' && document.getElementById("t4d2").innerHTML == '' && document.getElementById("t4d3").innerHTML == '') {

                return 4
            }
            if (document.getElementById("t5d1").innerHTML == '' && document.getElementById("t5d2").innerHTML == '' && document.getElementById("t5d3").innerHTML == '') {

                return 5
            }
            if (document.getElementById("t6d1").innerHTML == '' && document.getElementById("t6d2").innerHTML == '' && document.getElementById("t6d3").innerHTML == '') {
                return 6

            }
            if (document.getElementById("t7d1").innerHTML == '' && document.getElementById("t7d2").innerHTML == '' && document.getElementById("t7d3").innerHTML == '') {

                return 7
            }
            if (document.getElementById("t8d1").innerHTML == '' && document.getElementById("t8d2").innerHTML == '' && document.getElementById("t8d3").innerHTML == '') {
                return 8

            }
            else{
                return 0
            }
        }

       function setValue(){

        var lineNum = blankLine() 

        console.log("lineNum="+lineNum)

        if(lineNum==0){

            return false
        }
        var inputinfo = document.getElementById("inputinfo").value
        if(inputinfo.indexOf('粤') !== -1){
           // console.log("包含车牌----------------")

        }else{
            console.log("不包含车牌-------------")
            return 
        }

        if(inputinfo.indexOf('定位时间') !== -1){
           // console.log("包含定位时间----------------")

        }else{
            console.log("不包含定位时间-------------")
            return 
        }

        if(inputinfo.indexOf('行驶速度') !== -1){
            
            //console.log("包含行驶速度----------------")

        }else{
            console.log("不包行驶速度-------------")
            return 
        }

        if(inputinfo.indexOf('定位位置') !== -1){
            //console.log("包含定位位置----------------")

        }else{
            console.log("不包含定位位置-------------")
            return 
        }

        

        var strPosition1 = inputinfo.indexOf('粤')
        //console.log("粤--所在位置："+strPosition1)
        var strPosition2 = inputinfo.indexOf('驾')
        //console.log("驾--所在位置："+strPosition2)

        var str1 = inputinfo.substring(strPosition1, strPosition2).trim()

        console.log("获取车牌："+str1)


        var strPosition3 = inputinfo.indexOf('定位时间:')
        //console.log("粤--所在位置："+positionY)
        var strPosition4 = inputinfo.indexOf('定位经度:')
        //console.log("驾--所在位置："+positionJ)

        var str2 = inputinfo.substring(strPosition3+16, strPosition4).trim()

        console.log("获取定位时间："+str2)

        var strPosition5 = inputinfo.indexOf('定位位置:')
        //console.log("驾--所在位置："+positionJ)

        var str3 = inputinfo.substring(strPosition5+5).trim()

        console.log("获取定位位置："+str3)

        var strPosition6 = inputinfo.indexOf('行驶速度:')
        //console.log("粤--所在位置："+positionY)
        var strPosition7 = inputinfo.indexOf('km/h')
        //console.log("驾--所在位置："+positionJ)

        var str4 = inputinfo.substring(strPosition6+5, strPosition7).trim()

        console.log("获取行驶速度："+str4)


        
       
        document.getElementById("t"+lineNum+"d1").innerHTML = str2
        document.getElementById("t"+lineNum+"d2").innerHTML = str1
        document.getElementById("t"+lineNum+"d3").innerHTML = Math.round(str4)
        document.getElementById("t"+lineNum+"d4").innerHTML = str3
        


       }

    //    function getTablePosition (lineNum,tdNum){

    //     if(lineNum==1){
            
            
    //     }


    //    }



    </script>

    <script src="../js/bootstrap.bundle.min.js"></script>
</body>

</html>